
var nameArr = [];
var valueArr = [];
var sum;
$(function () {
    userWeek();
})


function userWeek() {

    sum = 0;
    $.ajax({
        contentType: "application/json",
        url: "/userWeek",
        method: "post",
        data: " ",
        dataType: "json",
        success: function (data) {
            nameArr = [];
            valueArr = [];
            nameArr=["周一","周二","周三","周四","周五","周六","周日"];
            for(var i=0;i<data.length;i++){
                valueArr.push(data[i])
                sum+=data[i]*1;
            }
            sum='本周新增用户:'+sum
            createUserEchars();
            createUserCurve();
        },
        error: function () {//状态不是200执行
            alert("网络繁忙");
        }
    })



}


function userMonth() {
    sum=0;
    $.ajax({
        contentType: "application/json",
        url: "/userMonth",
        method: "post",
        data: " ",
        dataType: "json",
        success: function (data) {
            nameArr = [];
            valueArr = [];
            nameArr=["第一周","第二周","第三周","第四周","第五周"];
            // var  obj=JSON.parse(data);
            for(var i=0;i<data.length;i++){
                valueArr.push(data[i])
                sum+=data[i]*1;
            }
            sum='本月新增用户:'+sum
            createUserEchars();
            createUserCurve();
        },
        error: function () {//状态不是200执行
            alert("网络繁忙");
        }
    })
}


function userHalfYear() {
    // alert("年的方法")
    // debugger;
    sum=0;
    $.ajax({
        contentType: "application/json",
        url: "/userYears",
        method: "post",
        data: " ",
        dataType: "text",
        success: function (data) {
            nameArr = [];
            valueArr = [];
            var obj=data.split("&&");

            var name=JSON.parse(obj[0]);
            for(var i=name.length-1;i>=0;i--){

                nameArr.push(name[i]);
            }
            var count=JSON.parse(obj[1])
            for(var i=0;i<count.length;i++){
                valueArr.push(count[i])
                sum+=count[i]*1;
            }
            sum='近半年新增用户:'+sum
            createUserEchars();
            createUserCurve();
        },
        error: function () {//状态不是200执行
            alert("网络繁忙");
        }
    })
}

function createUserCurve() {

    var chartDom = document.getElementById('main2');
    var myChart = echarts.init(chartDom);
    var option;


    option = {
        xAxis: {
            type: 'category',
            data: nameArr,
        },
        yAxis: {
            type: 'value'
        },

        series: [{
            data: valueArr,
            type: 'line',
            smooth: true
        }]
    };

    option && myChart.setOption(option);

}


function createUserEchars() {

// 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

// 指定图表的配置项和数据
    var option = {
        title: {
            text: sum,
            x:'600'
            // offsetCenter:[0,50]
        },
        tooltip: {},
        legend: {
            data: ['用户量']
        },
        xAxis: {
            data: nameArr
        },
        yAxis: {},
        series: [{
            name: '用户量',
            type: 'bar',
            barWidth: 55,
            data: valueArr
        }]
    };

// 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}


